﻿// ***********************************************************************
// Assembly         : Admin.Framework.Core.Repository
// Author           : xwltz
// Created          : 2019-05-25
//
// Last Modified By : xwltz
// Last Modified On : 2019-05-25
// ***********************************************************************
// <summary>
//  仓储接口
// </summary>
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using SqlSugar;

namespace Admin.Framework.Core.Repository.Interface
{
    public interface IRepository<TEntity> where TEntity : class, new()
    {
        /// <summary>
        /// 开放数据库Db接口 给那些喜欢写在UI的人用和处理事务多表查询和复杂的操作
        /// <para> 适合在一下情况使用:</para>
        /// <para>1 在同一事务中进行多表操作</para>
        /// <para>2 需要多表联合查询</para>
        /// </summary>
        /// <returns></returns>
        SimpleClient<TEntity> CurrentDb();
        /// <summary>
        /// 获取单条记录
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        TEntity GetSingle(Expression<Func<TEntity, bool>> exp = null);
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        List<TEntity> GetList();
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        List<TEntity> GetList(Expression<Func<TEntity, bool>> exp);
        // 新增
        bool Add(TEntity entity);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Update(TEntity entity);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Delete(TEntity entity);
    }
}
